package dao;

import org.apache.ibatis.annotations.*;
import pojo.Doctor;

import java.util.List;

public interface DoctorMapper {

    @Select("SELECT * FROM doctor")
    List<Doctor> findAll();

    @Select("SELECT * FROM doctor WHERE doc_id = #{docId}")
    Doctor findById(String docId);

    @Select("SELECT * FROM doctor WHERE user_id = #{userId}")
    Doctor findByUserId(String userId);

    @Select("SELECT * FROM doctor WHERE user_name = #{userName}")
    Doctor findByUserName(String userName);

    @Insert("INSERT INTO doctor(" +
            "doc_id, doc_name, sex, nation, work_year, " +
            "politicstatus, doc_title, education, introduction, " +
            "telephone, depart_id1, depart_id2, birthdate, " +
            "user_name, img, recommend, user_id) " +
            "VALUES(#{docId}, #{docName}, #{sex}, #{nation}, #{workYear}, " +
            "#{politicstatus}, #{docTitle}, #{education}, #{introduction}, " +
            "#{telephone}, #{departId1}, #{departId2}, #{birthdate}, " +
            "#{userName}, #{img}, #{recommend}, #{userId})")
    int addDoctor(Doctor doctor);

    @Update("UPDATE doctor SET " +
            "doc_name = #{docName}, " +
            "sex = #{sex}, " +
            "nation = #{nation}, " +
            "work_year = #{workYear}, " +
            "politicstatus = #{politicstatus}, " +
            "doc_title = #{docTitle}, " +
            "education = #{education}, " +
            "introduction = #{introduction}, " +
            "telephone = #{telephone}, " +
            "depart_id1 = #{departId1}, " +
            "depart_id2 = #{departId2}, " +
            "birthdate = #{birthdate}, " +
            "user_name = #{userName}, " +
            "img = #{img}, " +
            "recommend = #{recommend}, " +
            "user_id = #{userId} " +
            "WHERE doc_id = #{docId}")
    int updateDoctor(Doctor doctor);

    @Update("UPDATE doctor SET " +
            "doc_name = #{docName}, " +
            "sex = #{sex}, " +
            "nation = #{nation}, " +
            "work_year = #{workYear}, " +
            "politicstatus = #{politicstatus}, " +
            "doc_title = #{docTitle}, " +
            "education = #{education}, " +
            "introduction = #{introduction}, " +
            "telephone = #{telephone}, " +
            "depart_id1 = #{departId1}, " +
            "depart_id2 = #{departId2}, " +
            "birthdate = #{birthdate}, " +
            "user_name = #{userName}, " +
            "img = #{img}, " +
            "recommend = #{recommend}, " +
            "user_id = #{userId} " +
            "WHERE user_id = #{userId}")
    int updateDoctorByUserId(Doctor doctor);

    @Delete("DELETE FROM doctor WHERE doc_id = #{docId}")
    int deleteDoctor(String docId);
}